package com.aba.dormitory.system.student;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// 学生管理系统类 - 必须单独存放在StudentManagementSystem.java文件中
public class StudentManagementSystem {
    private Map<String, Student> students = new HashMap<>();
    private Scanner scanner = new Scanner(System.in);

    public void initializeData() {
        students.put("S001", new Student("S001", "123456", "1号楼101室"));
        students.put("S002", new Student("S002", "654321", "1号楼102室"));
        students.put("S003", new Student("S003", "112233", "2号楼201室"));
    }
    public Student login() {
        System.out.println("=== 学生登录 ===");
        int attempts = 3;
        
        while (attempts > 0) {
            System.out.print("学号: ");
            String studentId = scanner.nextLine();
            
            System.out.print("密码: ");
            String password = scanner.nextLine();
            
            Student student = students.get(studentId);
            if (student != null && student.verifyPassword(password)) {
                System.out.println("登录成功，欢迎 " + studentId + "!");
                return student;
            }
            
            attempts--;
            System.out.println("登录失败，剩余尝试次数: " + attempts);
        }
        
        System.out.println("尝试次数过多，程序退出。");
        return null;
    }

    public void showMenu(Student student) {
        boolean running = true;
        
        while (running) {
            System.out.println("\n=== 学生个人中心 ===");
            System.out.println("1. 查看寝室号");
            System.out.println("2. 退出");
            System.out.print("请选择: ");
            
            String choice = scanner.nextLine();
            
            switch (choice) {
                case "1":
                    System.out.println("您的寝室号是: " + student.getDormitory());
                    break;
                case "2":
                    running = false;
                    System.out.println("感谢使用，再见!");
                    break;
                default:
                    System.out.println("无效选择，请重新输入。");
            }
        }
    }

    public static void main(String[] args) {
        StudentManagementSystem system = new StudentManagementSystem();
        system.initializeData();
        
        Student student = system.login();
        if (student != null) {
            system.showMenu(student);
        }
    }
}